<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./css/swiper.css">
    <script src="./js/vue.js"></script>
    <script src="./js/swiper.js"></script>
</head>
<body>
    <!-- slot 分发技术实际是用于 项目开发的 功能封装 -->
    <div id="app">
        <h3>父组件</h3>
        <swiper-box>
            <div class="swiper-slide" style="height: 100px; background-color: brown;">slider1</div>
            <div class="swiper-slide" style="height: 100px; background-color: cadetblue;">slider2</div>
            <div class="swiper-slide" style="height: 100px; background-color: chocolate;">slider3</div>
        </swiper-box>
        <hr>
        <swiper-box :options="opt1">
            <div class="swiper-slide" style="height: 100px; background-color: brown;">slider1</div>
            <div class="swiper-slide" style="height: 100px; background-color: cadetblue;">slider2</div>
            <div class="swiper-slide" style="height: 100px; background-color: chocolate;">slider3</div>
            <template v-slot:view>
                <div class="swiper-pagination"></div>
            </template>
        </swiper-box>
    </div>
    <template id="swiperBox">
        <div class="swiper-container" ref="loop">
            <div class="swiper-wrapper">
                <slot></slot>
            </div>
            <slot name="view"></slot>
        </div>
    </template>
</body>
<script>
    Vue.component("SwiperBox",{
        template:"#swiperBox",
        props:{
            options:{
                type:Object,
                define(){
                    return {}
                }
            }
        },
        methods:{
            initSwiper() {
                this.$nextTick(()=>{
                    new Swiper(this.$refs.loop,this.options)
                })
            }
        },
        mounted() {
            this.initSwiper();
        }
    })

    new Vue({
        el:"#app",
        data:{
            opt1:{
                autoplay:true,
                pagination:{
                    el:'.swiper-pagination'
                }
            }
        }
    })
</script>
</html>